package com.example.cacheservice.controller;

import com.example.cacheservice.common.entity.User;
import com.example.cacheservice.service.UserService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Duration;
import java.util.Random;

/**
 * @author wuxinxin
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    Duration duration = Duration.ofSeconds(new Random().nextInt());

    /**
     * @see org.springframework.cache.CacheManager
     * @param id
     * @return
     */
    @GetMapping("/getUser/{id}")
    public User getUser(@PathVariable Integer id){
        System.out.println(duration.getSeconds());
        return userService.getUserById(id);
    }

    @PostMapping("/updateUserById")
    public User updateUserById(@RequestBody User user){
        return userService.updateUserById(user);
    }

    @DeleteMapping("/deleteUserById/{id}")
    public String deleteUserById(@PathVariable Integer id){
        userService.deleteUserById(id);
        return "success";
    }
}
